/**
 * Created by 功振 on 2016/1/30.
 */
var valuePath = "config/cp/value.js";
var value_ProtalPath = "config/cp/value_protal.js";

var wwwroot = 'new-docker/app';
var portalRoot = 'new-docker/modules/portal/app';

var scriptPath = ["new-docker/controller/route.js", "new-docker/controller/service.js" ,"new-docker/controllers/**/*.js", "new-docker/services/*.js", "new-docker/directives/*.js"];
var paths = {
    scripts: scriptPath
};
var portalPaths = {
    scripts: ["new-docker/modules/portal/config/config.js", "new-docker/modules/portal/services/*.js", "new-docker/modules/portal/directives/*.js", "new-docker/modules/portal/controllers/*.js"]
};


var gulp = require('gulp');
/*gulpLoadPlugins = require('gulp-load-plugins');
 plugins = gulpLoadPlugins();*/
var concat = require("gulp-concat");
var uglify = require('gulp-uglify');
//var cssmin = require('gulp-cssmin');
var cleanCSS = require('gulp-clean-css');
var wrap = require("gulp-wrap");

gulp.task("contact", function () {
    gulp.src(paths.scripts)
        //.pipe(wrap('(function(window){\n"use strict"\n<%= contents %>\n})(window);'))
        .pipe(wrap('<%= contents %>\n'))
        .pipe(concat('app.mid.js'))
        .pipe(gulp.dest(wwwroot))
        .pipe(uglify())
        .pipe(concat('app.mid.min.js'))
        .pipe(gulp.dest(wwwroot));
    gulp.src(portalPaths.scripts)
        //.pipe(wrap('(function(window){\n"use strict"\n<%= contents %>\n})(window);'))
        .pipe(wrap('<%= contents %>\n'))
        .pipe(concat('portal.js'))
        .pipe(gulp.dest(portalRoot))
        .pipe(uglify())
        .pipe(concat('portal.min.js'))
        .pipe(gulp.dest(portalRoot));
});

var cpComposePath = {
    "scripts": [wwwroot +"/app.mid.js", valuePath]
};
var cpPortalPath = {
    "scripts": [portalRoot +"/portal.js", value_ProtalPath]
};
gulp.task("cpvalue", function () {
    gulp.src(cpComposePath.scripts)
        //.pipe(wrap('(function(window){\n"use strict"\n<%= contents %>\n})(window);'))
        .pipe(wrap('<%= contents %>\n'))
        .pipe(concat('app.js'))
        .pipe(gulp.dest(wwwroot))
       /* .pipe(uglify())
        .pipe(concat('app.min.js'))
        .pipe(gulp.dest(wwwroot));*/
    gulp.src(cpPortalPath.scripts)
    //.pipe(wrap('(function(window){\n"use strict"\n<%= contents %>\n})(window);'))
        .pipe(wrap('<%= contents %>\n'))
        .pipe(concat('portal.js'))
        .pipe(gulp.dest(portalRoot))
});

var cpPaths = {
    "scripts": scriptPath.concat([valuePath])
}
var portalPaths_all = {
    "scripts": portalPaths.scripts.concat([value_ProtalPath])
}
gulp.task("contactAll", function () {
    gulp.src(cpPaths.scripts)
        //.pipe(wrap('(function(window){\n"use strict"\n<%= contents %>\n})(window);'))
        .pipe(wrap('<%= contents %>\n'))
        .pipe(concat('app.js'))
        .pipe(gulp.dest(wwwroot))
        .pipe(uglify())
        .pipe(concat('app.min.js'))
        .pipe(gulp.dest(wwwroot));
    gulp.src(portalPaths_all.scripts)
        //.pipe(wrap('(function(window){\n"use strict"\n<%= contents %>\n})(window);'))
        .pipe(wrap('<%= contents %>\n'))
        .pipe(concat('portal.js'))
        .pipe(gulp.dest(portalRoot))
        .pipe(uglify())
        .pipe(concat('portal.min.js'))
        .pipe(gulp.dest(portalRoot));
});

